﻿unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, IdBaseComponent,
  IdComponent, IdTCPConnection, IdTCPClient, IdHTTP, IdHMACSHA1, IdCoderMIME,
  Vcl.ComCtrls;

type
  TForm1 = class(TForm)
    IdHTTP1: TIdHTTP;
    Button2: TButton;
    ProgressBar1: TProgressBar;
    procedure Button2Click(Sender: TObject);
  private
    procedure idhttp_onwork(ASender: TObject; AWorkMode: TWorkMode;
      AWorkCount: Int64);
    procedure idhttp_beginwork(ASender: TObject; AWorkMode: TWorkMode;
      AWorkCountMax: Int64);
    procedure idhttp_endwork(ASender: TObject; AWorkMode: TWorkMode);
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

uses
  IdURI, Soap.EncdDecd, System.JSON,  IdGlobal,IdMultipartFormData,
  DateUtils, qiniuUitls;

{$R *.dfm}




procedure TForm1.Button2Click(Sender: TObject);
var
  qiniu: TQiniu;
begin
  qiniu := TQiniu.Create('', '', '');
  try
    qiniu.OnWork := self.idhttp_onwork;
    qiniu.OnWorkBegin := self.idhttp_beginwork;
    qiniu.OnWorkEnd := self.idhttp_endwork;
    ShowMessage(qiniu.UpFileEx('d:\test.txt'));
  finally
    qiniu.Free;
  end;

end;

procedure TForm1.idhttp_beginwork(ASender: TObject; AWorkMode: TWorkMode;
  AWorkCountMax: Int64);
begin
    ShowMessage('begin upload');
  ProgressBar1.Max:=AWorkCountMax;
      ProgressBar1.Min := 0;
    ProgressBar1.Position:=0;
end;

procedure TForm1.idhttp_endwork(ASender: TObject; AWorkMode: TWorkMode);
begin
  ProgressBar1.Position:=0;
  ShowMessage('OK');
end;

procedure TForm1.idhttp_onwork(ASender: TObject; AWorkMode: TWorkMode;
  AWorkCount: Int64);
begin
   ProgressBar1.Position:=AWorkCount ;
end;

end.
